<?php
class Mincoding_VendorConnect_Model_Resource_Reportvendorcontract extends Mage_Core_Model_Resource_Db_Abstract
{
    protected function _construct()
    {
    	$this->_init("vendorconnect/contract", "");
    }
    
    public function loadContractDetails($id)
    {
        $contractModel = Mage::getModel('vendorconnect/contract')->load($id);
        return $contractModel;
    }
    public function loadVendorDetails($id)
    {
        $vendorModel = Mage::getModel('vendorconnect/vendors')->load($id);
        return $vendorModel;
    }
    
    public function getProductLinkedContract($id)
    {
        $productIds = Mage::getResourceModel('vendorconnect/contractproduct')->getProductIdsSelected($id);
        if ( $productIds )
        {
            $productIdStr = implode(',',$productIds);
            $connectionRead = $this->_getReadAdapter();
            //$table = $connectionRead->getTableName('mincoding_contract_product_flat');
            $productNameTable = Mage::helper('vendorconnect')->getReaderConnection()->getTableName('catalog_product_entity_varchar');
            
            $attributeModel = Mage::getModel('catalog/product')->getResource()->getAttribute("name");
            //echo "<pre>"; var_dump($attribute_id);die;

            $select = $connectionRead->select()
                ->from($productNameTable, array('id' => 'entity_id','name' => 'value'));  
            $select->where("entity_id IN (".$productIdStr.")");    
            $select->where("attribute_id =? ",$attributeModel->getId());    
            //echo $select->__toString();die;
            return $connectionRead->fetchAll($select);  
        }
        return false;
        
    }
}